﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x02000034 RID: 52
[RequireComponent(typeof(Slider))]
public class ColorSlider : MonoBehaviour
{
	// Token: 0x06000118 RID: 280 RVA: 0x0000C920 File Offset: 0x0000AB20
	private void Awake()
	{
		this.slider = base.GetComponent<Slider>();
		this.hsvpicker.onValueChanged.AddListener(new UnityAction<Color>(this.ColorChanged));
		this.hsvpicker.onHSVChanged.AddListener(new UnityAction<float, float, float>(this.HSVChanged));
		this.slider.onValueChanged.AddListener(new UnityAction<float>(this.SliderChanged));
	}

	// Token: 0x06000119 RID: 281 RVA: 0x0000C990 File Offset: 0x0000AB90
	private void OnDestroy()
	{
		this.hsvpicker.onValueChanged.RemoveListener(new UnityAction<Color>(this.ColorChanged));
		this.hsvpicker.onHSVChanged.RemoveListener(new UnityAction<float, float, float>(this.HSVChanged));
		this.slider.onValueChanged.RemoveListener(new UnityAction<float>(this.SliderChanged));
	}

	// Token: 0x0600011A RID: 282 RVA: 0x0000C9F4 File Offset: 0x0000ABF4
	private void ColorChanged(Color newColor)
	{
		this.listen = false;
		switch (this.type)
		{
		case ColorValues.R:
			this.slider.normalizedValue = newColor.r;
			break;
		case ColorValues.G:
			this.slider.normalizedValue = newColor.g;
			break;
		case ColorValues.B:
			this.slider.normalizedValue = newColor.b;
			break;
		case ColorValues.A:
			this.slider.normalizedValue = newColor.a;
			break;
		}
	}

	// Token: 0x0600011B RID: 283 RVA: 0x0000CA8C File Offset: 0x0000AC8C
	private void HSVChanged(float hue, float saturation, float value)
	{
		this.listen = false;
		switch (this.type)
		{
		case ColorValues.Hue:
			this.slider.normalizedValue = hue;
			break;
		case ColorValues.Saturation:
			this.slider.normalizedValue = saturation;
			break;
		case ColorValues.Value:
			this.slider.normalizedValue = value;
			break;
		}
	}

	// Token: 0x0600011C RID: 284 RVA: 0x0000CAF8 File Offset: 0x0000ACF8
	private void SliderChanged(float newValue)
	{
		if (this.listen)
		{
			newValue = this.slider.normalizedValue;
			this.hsvpicker.AssignColor(this.type, newValue);
		}
		this.listen = true;
	}

	// Token: 0x04000218 RID: 536
	public ColorPicker hsvpicker;

	// Token: 0x04000219 RID: 537
	public ColorValues type;

	// Token: 0x0400021A RID: 538
	private Slider slider;

	// Token: 0x0400021B RID: 539
	private bool listen = true;
}
